package com.web.hilover.config;

import com.web.hilover.interceptor.AdminInterceptor;
import com.web.hilover.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    
    @Autowired
    private LoginInterceptor loginInterceptor;
    
    @Autowired
    private AdminInterceptor adminInterceptor;
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 静态资源映射
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        
        // 上传文件访问映射
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:uploads/");
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(
                    "/login", "/register", "/", "/index", 
                    "/static/**", "/uploads/avatar/**", "/avatar/**", "/uploads/**", "/error",
                    "/captcha", "/api/login", "/api/register",
                    "/couples", "/couples/search"  // 也放行情侣列表和搜索页面
                )
                .addPathPatterns("/**");
                
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/admin/**");
    }
} 